// API服务层 - 预留接口对接方式
class ApiService {
  constructor() {
    this.baseURL = process.env.VITE_API_BASE_URL || '/api'
  }

  // 获取任务列表
  async getTasks(params = {}) {
    try {
      // TODO: 对接实际接口
      // const response = await fetch(`${this.baseURL}/tasks`, {
      //   method: 'GET',
      //   headers: this.getHeaders(),
      //   params
      // })
      // return await response.json()
      
      // 模拟数据
      return this.mockTasks()
    } catch (error) {
      console.error('获取任务列表失败:', error)
      throw error
    }
  }

  // 上传选中的任务
  async uploadTasks(tasks) {
    try {
      // TODO: 对接实际接口
      // const response = await fetch(`${this.baseURL}/tasks/upload`, {
      //   method: 'POST',
      //   headers: this.getHeaders(),
      //   body: JSON.stringify({ tasks })
      // })
      // return await response.json()
      
      // 模拟上传成功
      return { success: true, message: '上传成功', data: tasks }
    } catch (error) {
      console.error('上传任务失败:', error)
      throw error
    }
  }

  // 获取任务详情
  async getTaskDetail(taskId) {
    try {
      // TODO: 对接实际接口
      // const response = await fetch(`${this.baseURL}/tasks/${taskId}`)
      // return await response.json()
      
      return this.mockTasks().find(task => task.id === taskId)
    } catch (error) {
      console.error('获取任务详情失败:', error)
      throw error
    }
  }

  // 请求头配置
  getHeaders() {
    const headers = {
      'Content-Type': 'application/json',
    }
    
    // TODO: 添加认证token
    // const token = localStorage.getItem('auth_token')
    // if (token) {
    //   headers['Authorization'] = `Bearer ${token}`
    // }
    
    return headers
  }

  // 模拟任务数据
  mockTasks() {
    return [
      {
        id: 1,
        title: '待办001',
        type: 'todo',
        time: '2025.09.10，19:23:32',
        selected: false,
        icon: '/assets/CodeBubbyAssets/10069_20065/11.svg',
        actionIcon: '/assets/CodeBubbyAssets/10069_20065/12.svg',
        bgColor: 'bg-primary-600',
        description: '待办任务描述',
        priority: 'high',
        status: 'pending'
      },
      {
        id: 2,
        title: '知会001',
        type: 'notice',
        time: '2025.09.10，15:33:45',
        selected: false,
        icon: '/assets/CodeBubbyAssets/10069_20065/9.svg',
        actionIcon: '/assets/CodeBubbyAssets/10069_20065/10.svg',
        bgColor: 'bg-primary-50',
        description: '知会任务描述',
        priority: 'medium',
        status: 'read'
      },
      {
        id: 3,
        title: '投诉001',
        type: 'complaint',
        time: '2025.09.10，11:23:42',
        selected: false,
        icon: '/assets/CodeBubbyAssets/10069_20065/6.svg',
        actionIcon: '/assets/CodeBubbyAssets/10069_20065/7.svg',
        bgColor: 'bg-primary-50',
        description: '投诉任务描述',
        priority: 'high',
        status: 'processing'
      }
    ]
  }
}

// 创建单例实例
export const apiService = new ApiService()

// 导出所有方法
export default apiService